<?php

namespace App\Http\Requests;

/**
 * 系统角色验证器
 * @package App\Http\Requests
 */
class AdminSysRolePost extends AdminBaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $exceptId = (int) $this->input('role_id', 0);
        return [
            'name' => 'required|unique:sys_roles,name,'.$exceptId.',role_id',
            'display_name' => 'required',
            'parent_id' => 'required',
        ];
    }

    /**
     * 定义错误信息
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => '角色定义名不能为空',
            'name.unique' => '角色定义名已存在',
            'display_name.required' => '角色显示名不能为空',
        ];
    }
}
